using System;
using AtDevice;

namespace GtkControls
{
    
    
    public partial class PhoneBookEditEntryWindow : Gtk.Window
    {
        private PhoneBookEntry _entry;
        private IPhoneBook _phonebook;
        
        public PhoneBookEditEntryWindow(PhoneBookEntry entry, IPhoneBook phonebook) : 
                base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            _entry = entry;
            _phonebook = phonebook;
            SetupDialog();
        }
        
        private void SetupDialog()
        {
            mobileNumberEntry.Text = _entry.MobileNumber;
            nameEntry.Text = _entry.Name;
            officeEntry.Text = _entry.OfficeNumber;
            homeNumberEntry.Text = _entry.HomeNumber;
            emailEntry.Text = _entry.Email;
            remarksEntry.Buffer.Text = _entry.Remarks;
        }

        protected virtual void OnSaveButtonClicked (object sender, System.EventArgs e)
        {
            PhoneBookEntry entry = new PhoneBookEntry()
            {
                Index = _entry.Index,
                MobileNumber = mobileNumberEntry.Text,
                Name = nameEntry.Text,
                OfficeNumber = officeEntry.Text,
                HomeNumber = homeNumberEntry.Text,
                Email = emailEntry.Text,
                Remarks = remarksEntry.Buffer.Text
            };
            _phonebook.UpdateEntry(entry);
            this.Destroy();
        }

        protected virtual void OnCancelButtonClicked (object sender, System.EventArgs e)
        {
            this.Destroy();
        }
    }
}
